<template>
	<view>
		<view class="wrap">
			<block>
				<view class="statistics-list" @tap.stop="openInfo(index)" v-if="newsList.length > 0" v-for="(item,index) in newsList" :key="index" >
					<view class="userInfo flex align-center">
						
						<view class="headimg flex align-center">
							<image :src="item.avatar" class="head-img"></image>
						</view>
						<view class="right">
							<view class="username">
								<text class="user-name fl">{{item.nickname}}</text>
								<text class="time-text fl" :class="'time-text'+item.time_status">{{item.time_text}}</text>
							</view>
							<view class="desc">
								<text>{{item.type_text}}<text class="zhanwei-text"></text></text>
								
								<text>{{item.createtime}}<text class="zhanwei-text"></text></text>
								
								<text>{{item.look_sum}}人看过</text>
							</view>
						</view>
					</view>
					<view class="s-title">
						{{item.title}}
					</view>
					<view class="list-botton">
						<text class="iconfont icon-shanchu" @tap.stop="showOpe(index)"></text>
					</view>
				</view>	
				<view class="show-nomore" v-if="paramsInfo.showNoMore == true">没有更多内容了</view>	
				<view class="zhanwei"></view>
				<!-- 视频 -->
				
			</block>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newsList:[],
				paramsInfo:{
					current_page:0,
					last_page:0,
					per_page:10,
					showNoMore:false,
				}
				
			}
		},
		methods: {
			openInfo(index){
				var info = this.newsList[index];
				if(info.type == 2)
				{
					var url = '/pages/form/daka/detail?s_id='+info.s_id;
				}else{
					var url = '/pages/form/statistics/detail?s_id='+info.s_id
				}
				this.$api.navigateTo(url);
			},
			showOpe(index){
				var that = this;
				var info = that.newsList[index];
				that.$api.showModal('确认删除','',function(res){
					if(res == 'yes')
					{
						that.delInfo(info.s_id,index);
					}
				})
			},
			delInfo(s_id,index){
				var that = this;
				that.$api.loadingMsg('正在删除');
				that.$http.post('statistics/delInfo',{
					s_id
				}).then(res=>{
					that.$api.msg(res.msg);
					if(res.code == 1)
					{
						that.newsList.splice(index,1)
					}
				});
			},
			getList(){
				var that = this;
				var info = that.paramsInfo;
				var current_page = info.current_page?info.current_page:0;
				var last_page = info.last_page?info.last_page:1;
				if(current_page == last_page)
				{
					that.showNoMore();
					return ;
				}
				that.$api.loadingMsg('正在加载');
				var getPage = current_page + 1; //要请求第几页的数据
				that.$http.get('user/getAllStatisticsList',{
					params:{
						page:getPage,
						per_page:info.per_page
					},
				}).then(res=>{
					if(res.code == 1)
					{
						var resData = res.data;
						var newsList = that.newsList.concat(resData.data); 
						that.newsList = newsList;
						//把每个下面的数据保存给tab
						info.current_page = resData.current_page;
						info.last_page = resData.last_page;
						//重置状态
						setTimeout(()=>{
							var haveMore = (info.current_page == info.last_page || resData.data.length == 0)?false:true;
							if(haveMore == false)
							{ 
								that.showNoMore();
							}
						},20)
					}else{
						that.newsList = [];
					}
				})
			},
			showNoMore(){
				this.paramsInfo.showNoMore = true;
			}
		},
		onLoad(){
			this.getList();
		},
		onPullDownRefresh(){
			this.newsList = [];
			this.paramsInfo = {
				current_page:0,
				last_page:0,
				per_page:10,
				showNoMore:false,
			}
			this.getList();
			uni.stopPullDownRefresh()
		},
		onReachBottom(){
			this.getList();
		}
	}
</script>

<style lang="scss">
	
.statistics-list{
		background: #FFFFFF;
		width: 100%;
		margin: 0rpx 0% 20rpx 0;
		padding: 10rpx 3%;
		position: relative;
		.list-botton{
			height: 60rpx;
			line-height: 60rpx;
			width: 100%;
			font-size: 26rpx;
			position: relative;
			
			.iconfont{
				position: absolute;
				right: 8px;
				top: 0;
				font-size: 40rpx;
				color: #26C390;
			}
			.icon-fenxiang{
				right: 80rpx;
			}
			.icon-guanli{
				font-size: 36rpx;
				top: -2rpx;
			}
		}
		.s-title{
			padding: 10rpx 0;
			font-size: 28rpx;
		}
		.userInfo{
			height: 100rpx;
			.headimg{
				.head-img{
					width: 70rpx;
					height: 70rpx;
					border-radius: 50%;
					margin-right: 10rpx;
				}
			}
			.right{
				.username{
					height: 50rpx;
					line-height: 60rpx;
					font-size: 28rpx;
					font-weight: 600;
					.user-name{
						display: inline-block;
						max-width: 450rpx;
						height: 100%;
						overflow: hidden;
					}
					.time-text{
						display: inline-block;
						padding: 0 16rpx;
						height: 30rpx;
						line-height: 30rpx;
						border-radius: 24rpx;
						margin-left: 11rpx;
						font-size: 22rpx;
						font-weight: normal;
						margin-top: 12rpx;
						border: 2rpx solid #EDEDED;
					}
					.time-text-1{
						background: #EDEDED;
						color: #999999;
					}
					.time-text-2{
						background: #EDEDED;
						color: #999999;
						
					}
					.time-text1{
						color: #3B935E;
						border: 2rpx solid #3B935E;
					}
				}
				
				.desc{
					height: 50rpx;
					line-height: 50rpx;
					text{
						display: inline-block;
						font-size: 24rpx;
						color: #999999;
						padding-right: 20rpx;
						position: relative;
					}
					.zhanwei-text{
						width: 2rpx;
						height: 24rpx;
						background-color: #999999;
						padding: 0;
						position: absolute;
						top: 14rpx;
						right: 10rpx;
					}
				}
				
			}
		}
	}
</style>
